package com.example.myapplication
import android.annotation.SuppressLint
import android.os.Bundle
import android.view.ViewGroup
import android.widget.Button
import android.widget.LinearLayout
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class MainActivity : AppCompatActivity() {
    @SuppressLint("SetTextI18n")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
//        enableEdgeToEdge()
//        setContentView(R.layout.activity_main)
//
//        val button = findViewById<Button>(R.id.button) // 将Button控件赋值给一个变量
//        val textView = findViewById<TextView>(R.id.textView)
//        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
//            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
//            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
//            insets
//        }
//
        val linearLayout = LinearLayout(this)
        linearLayout.orientation = LinearLayout.VERTICAL

        val textView = TextView(this)
//        textView.width = ViewGroup.LayoutParams.MATCH_PARENT
//        textView.height = ViewGroup.LayoutParams.WRAP_CONTENT
        textView.layoutParams=ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT)
        textView.textSize = 35f
        textView.text = getString(R.string.textView)
        linearLayout.addView(textView)

        val button = Button(this)
        button.width = ViewGroup.LayoutParams.MATCH_PARENT
        button.height = ViewGroup.LayoutParams.WRAP_CONTENT
        button.text = getString(R.string.button)
        linearLayout.addView(button)

        setContentView(linearLayout)

        button.setOnClickListener{  // 使用button变量来获取Button控件的点击事件
           textView.text = resources.getString(R.string.clicked)
       }
    }
}